package ogdkp.actions;

import ogdkp.dialog.AddLootDialog;
import ogdkp.om.Player;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;

public class AddLootAction extends Action {

	private final Player player;

	private final TreeViewer viewer;

	private final AddLootActionInfo info;

	public AddLootAction(final Player player, final TreeViewer viewer, final AddLootActionInfo info) {
		setText("Add Loot");
		setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJ_ADD));
		this.player = player;
		this.viewer = viewer;
		this.info = info;
	}

	@Override
	public void run() {
		final AddLootDialog dialog = new AddLootDialog(viewer.getControl().getShell(), player, info);
		if (dialog.open() == dialog.OK) {
			player.addLoot(dialog.getName(), Integer.parseInt(dialog.getValue()));
			viewer.refresh();
		}
	}

}
